import {createRouter, createWebHashHistory} from 'vue-router'
import Home from '../views/sys/Home.vue'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            name: 'home',
            component: Home,
            redirect: 'welcome',
            children: [
                {path: 'welcome', component: () => import('@/views/sys/Welcome.vue')}
            ]
        }, {
            path: '/login',
            name: 'login',
            component: () => import('@/views/sys/Login.vue')
        }
    ]
})
const allow = ['/login']

//npm i nprogress --save
// @ts-ignore
import np from 'nprogress'
import 'nprogress/nprogress.css'
//设置不显示右下角的旋转加载动画
np.configure({showSpinner:false})
router.beforeEach((to, from, next) => {
    //console.log(to)
    //console.log(from)
    //console.log(next)

    // if (allow.includes(to.path)) {
    //     next()
    // } else if (localStorage.getItem("token")) {
    //     next()
    // } else {
    //     next("/login")
    // }
    np.start()
    next()
})


router.afterEach(()=>{
    np.done()
})
export default router
